clear all;close all;clc

Hard0_Soft1 =1
figure('position',[100 100 700 450]);
for reverse = 1:2
    % ===
    R_Soft_control_noise_Cond1 = [ 64/100 45/100]; % left -60, right +60

    R_Soft_noise_Cond1 = [ 95/100 94/100]; % % left -60, right +60

    R_Soft_noise_Cond2 = [ 95/100 94/100]; % % left -15, right +15

    R_Soft_noise_Cond3 = [ 97/100 96/100]; % % 0, right +5

    R_Soft_noise_Cond4 = [ 64/100 43/100]; % % Right +85, right +90

    R_Soft_noise_Cond5 = [ 80/100 77/100]; % % Right +75, right +105

    R_Soft_noise_Cond6 = [ 94/100 91/100]; % % Back 180, 175

    titles={'A. Front, −60^{o}&+60^{o}','B. Front, −15^{o}&+15^{o}','C. Front, 0^{o}&+5^{o}','D. Side, +85^{o}&+90^{o}','E. Side, +65^{o}&+90^{o}','F. Back, +180^{o}&+175^{o}'};

    n=100;
    alpha=0.05;
    outP=f_out_plot;
    %     mean(R_control_noise_Cond1)
    for i=1:6
        subplot('position',outP(i,:))
        if Hard0_Soft1==0
            eval(['tem = R_Processed_noise_Cond' num2str(i) ';'])
        elseif Hard0_Soft1==1
            eval(['tem = R_Soft_noise_Cond' num2str(i) ';'])
        end
        pbar = [R_Soft_control_noise_Cond1' tem' ].*100;
        mean(tem)
        if reverse == 1
            c=bar(1:2, [pbar(1,:); 0 0],0.45);hold on;
            c(1).FaceColor = [0.2        0.5        0.341];
            c(2).FaceColor = [  0.95        0.625        0.298];
        else
            dd=bar(1:2,[0 0; pbar(2,:)],0.45)
            dd(1).FaceColor = [0.1 0.1 0.1];
            dd(2).FaceColor = [ 0.5 0.5 0.5];

            for icond = 1:2
                for ib = 1:length(pbar)
                    CI(icond,ib) = f_confid_I(n,pbar(ib,icond)./100,alpha).*100;
                end
                hold on;
                errorbar((1:2)+0.3.*(icond-1.5),pbar(:,icond),CI(icond,:),'k.');                
            end
            set(gca,'xtick',1:2)

            xlabel('Sentence Group #');
            ylabel('Percent Correct (%)')
            box off;
            ylim([0 115])
            title(titles{i})
            if i==2
                %             if Hard0_Soft1==0
                %                 t=text(5,145,['HRTF-1, Hard Mask, SNR = 0 dB'],'horizontalalignment','center');set(t,'fontsize',12)
                %             else
                t=text(1.5,145,['HRTF-3, Soft Mask, SNR = 3 dB'],'horizontalalignment','center');set(t,'fontsize',12)
                %             end
            end
            for igroup = 1:2
                p1=pbar(igroup,1)./100;
                p2=pbar(igroup,2)./100;
                out = f_ztest(p1,p2,100,100);
                if out.p < 0.05/6 & p1<p2
                    plot(igroup,max(pbar(igroup,:))+CI(1,igroup)+2,'k*');
                end
                set(gca,'xticklabel',[8 8])
            end
            if i==4
                hh=legend('Control, Rev','Processed, Rev','Control, No-R','Processed, No-R')
                hh.Position = [0.21 0.30 0.1 0.1]
%                 hh.IconColumnWidth  = 6
                legend boxoff
            end
        end
    end

%     if Hard0_Soft1==0
%         exportgraphics(gcf, 'BB_S3_Figure6_HardResults.png', 'Resolution', 600,'ContentType', 'vector')
%     elseif Hard0_Soft1==1
        exportgraphics(gcf, 'BB_S3_Figure12_Reverse.png', 'Resolution', 600,'ContentType', 'vector')
%     end

end
out = f_ztest(pbar(1,1)/100,pbar(2,1)/100,100,100)